using System.Net.Sockets;

namespace Hsenl.Network {
    public static class NetworkPoolExtension {
        public static bool TryRentIOCP<T>(this NetworkPool<T> self, out T receiver, Socket socket, SocketBufferKind bufferKind = SocketBufferKind.Memory) where T : class, IIOCP {
            if (self.TryRent(out var result)) {
                result.Init(socket, bufferKind);
                receiver = result;
                return true;
            }

            receiver = null;
            return false;
        }

        public static void ReturnIOCP<T>(this NetworkPool<T> self, T tcpReceiver) where T : class, IIOCP {
            self.Return(tcpReceiver);
        }
    }
}